package com.example.gaojt.androiddemo.cleanDemo;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;

import com.clean.spaceplus.cleansdk.junk.cleanmgr.CleanCallback;
import com.clean.spaceplus.cleansdk.junk.cleanmgr.CleanManager;
import com.clean.spaceplus.cleansdk.junk.cleanmgr.CleanManagerImpl;
import com.clean.spaceplus.cleansdk.junk.engine.bean.GroupJunkInfo;
import com.clean.spaceplus.cleansdk.junk.engine.bean.JunkGroupTitle;
import com.clean.spaceplus.cleansdk.junk.engine.bean.JunkModel;
import com.clean.spaceplus.cleansdk.junk.engine.bean.JunkScanSetting;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created by gaojt on 7/11/17.
 */

public class CleanDemoActivity extends Activity implements CleanCallback {

    private static final String TAG = "CleanDemoActivity";
    List<JunkGroupTitle> mGroupList;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initJunkData();

    }

    public void initJunkData() {
        mGroupList = Collections.synchronizedList(new ArrayList<JunkGroupTitle>());
        List<GroupJunkInfo> groupJunkInfoList = new ArrayList<GroupJunkInfo>();
        groupJunkInfoList.add(new GroupJunkInfo("应用缓存", 0, JunkGroupTitle.ITEM_APPCACHE_FLAG));
        groupJunkInfoList.add(new GroupJunkInfo("卸载残留", 0, JunkGroupTitle.ITEM_LEFTCACHE_FLAG));
        groupJunkInfoList.add(new GroupJunkInfo("广告垃圾", 0, JunkGroupTitle.ITEM_ADCACHE_FLAG));
        groupJunkInfoList.add(new GroupJunkInfo("无用安装包", 0, JunkGroupTitle.ITEM_APKCACHE_FLAG));
        groupJunkInfoList.add(new GroupJunkInfo("系统缓存", 0, JunkGroupTitle.ITEM_SYSCACHE_FLAG));
        groupJunkInfoList.add(new GroupJunkInfo("内存缓存", 0, JunkGroupTitle.ITEM_MEMCACHE_FLAG));
        for (GroupJunkInfo item : groupJunkInfoList) {
            JunkGroupTitle group = new JunkGroupTitle();
            group.groupIcon = item.getGroupIcon();
            group.groupName = item.getGroupTitle();
            group.groupSize = "";
            group.groupFlag = item.getGroupFlag();
            mGroupList.add(group);
        }

        CleanManager mCleanMgr = new CleanManagerImpl(mGroupList);
        JunkScanSetting setting = new JunkScanSetting();
        setting.setMbScanSdCache(true);
        mCleanMgr.setScanSetting(setting);
        mCleanMgr.setCallback(this);
        setting.setMbScanAdDirCache(true);
        setting.setMbScanApkFile(true);
        setting.setMbScanProcess(true);
        setting.setMbScanRubbish(true);
        setting.setMbScanSdCache(true);
        setting.setMbScanSysCache(true);
        mCleanMgr.setScanSetting(setting);
//设置是否从缓存数据里面取,主要是在第一次进入后再次进入不会再扫描
//setting.setMbScanCacheEnable(true);

        mCleanMgr.startScan();
    }


    @Override
    public void onScanStart() {
        Log.d(TAG, "onScanStart: thread = " + Thread.currentThread());
    }

    @Override
    public void onScanNewDir(String s) {
        Log.d(TAG, "onScanNewDir: s = " + s);
    }

    @Override
    public void onScanEnd(boolean isForceStop, final List<JunkModel> datas, final long checkedSize,
                          long totalSize, long memorySize) {
        Log.d(TAG, "onScanEnd: isForceStop = " + isForceStop + ",checkedSize = "
                + checkedSize + ",totalSize = " + totalSize
                + ",memorySize = " + memorySize + ",thread = " + Thread.currentThread());

    }

    @Override
    public void onUpdateCheckedSize(long l) {
        Log.d(TAG, "onUpdateCheckedSize: l = " + l + ",thread = " + Thread.currentThread());
    }

    @Override
    public void onCleanStart() {
        Log.d(TAG, "onCleanStart: thread = " + Thread.currentThread());
    }

    @Override
    public void onCleanEnd(long l) {
        Log.d(TAG, "onCleanEnd: l = " + l + ",thread = " + Thread.currentThread());
    }

    @Override
    public void onScanProgress(int i) {
        Log.d(TAG, "onScanProgress: i = " + i + ",thread = " + Thread.currentThread());
    }

    @Override
    public void onItemScanFinish(int i, long l) {
        Log.d(TAG, "onItemScanFinish: i = " + i + ",l = " + l + ",thread = " + Thread.currentThread());
    }

    @Override
    public void onInCacheTime() {
        Log.d(TAG, "onInCacheTime: thread = " + Thread.currentThread());
    }

    @Override
    public void onNeedNotClean() {
        Log.d(TAG, "onNeedNotClean: thread = " + Thread.currentThread());
    }
}
